import { getLevelSecond, getPosIDs } from '@/utils';

/**
 * 切换列表
 * @param curRes 权限数据
 * @returns
 */
const ManageTabSwitch = (curRes: Record<string, any>) => {
  /**
   * 待办还是已办
   * @taskType  true :已办   false : 待办
   */
  const HandCheckParams = (taskType: boolean) => {
    if (curRes?.['/contractController/dealHomePage']) {
      return {
        dealState: taskType,
        sort: taskType ? 'END_TIME_' : 'CREATE_TIME_',
        queryType: '0',
        // params: 'ownCompanyID',
        params: 'ownerID',
      };
    } else if (curRes?.['/contractController/taskManage/0/1']) {
      return {
        assigneePositionID: getLevelSecond(),
        dealState: taskType,
        sort: taskType ? 'END_TIME_' : 'CREATE_TIME_',
        queryType: '1',
        // params: 'ownDepartmentID',
        params: 'ownerID',
      };
    } else if ('/contractController/dealedHomePage') {
      return {
        assigneePositionID: getPosIDs(),
        dealState: taskType,
        sort: taskType ? 'END_TIME_' : 'CREATE_TIME_',
        queryType: '2',
        params: 'ownerID',
      };
    } else {
      return {};
    }
  };

  return [
    {
      title: '待办',
      key: 'NeedToDoTasks',
      visible: curRes?.['/contractController/dealHomePage'] || false,
      md: 2,
      sm: 24,
      params: HandCheckParams(false),
    },
    {
      title: '已办',
      key: 'CompletedTasks',
      visible: curRes?.['/contractController/dealedHomePage'] || false,
      md: 2,
      sm: 24,
      params: HandCheckParams(true),
    },
  ];
};
export { ManageTabSwitch };
